package main.java.com.cooljie.filter;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * Created by ACER on 2017/6/12.
 */
public class loginFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest)req;
        HttpServletResponse response = (HttpServletResponse)resp;
        HttpSession session = request.getSession();

        String username="admin";
        System.out.println(session.getAttribute("admin")+"***");

        if(!(username.equals(session.getAttribute("admin")))){
            System.out.println(">>>>>>>>");
request.getRequestDispatcher("/login.jsp").forward(request,response);
return;
        }
chain.doFilter(request,response);
    }

    @Override
    public void destroy() {

    }
}
